<script setup>
import { ref } from 'vue';
import LayoutFooter from '../Layout/components/LayoutFooter.vue';
import LayoutNav from '../Layout/components/LayoutNav.vue';
import { getGoodsByShop, getGoodsByCategory, getCategoryByShop, searchShopGoods } from '@/api/shop'


const search = ref('')

const shop = ref(
  {
    name: '桃禧',
    logo: 'https://seal-img.nos-jd.163yun.com/obj/w5rCgMKVw6DCmGzCmsK-/46117677885/45b8/dd8b/0039/c69a6125997cc259cb9709c4b9d2539e.jpg',
    desc: '为用户提供优质棉绒衬衫，价格合适，穿得舒适',
    phone: 1828652233,
    rate: 4.2,
    location:'浙江省宁波市余姚市凤山街道邵竹路6号'
  }
);

const goodlist = ref([
  {
    id: 1,
    name: '时尚连衣裙',
    desc: '简约时尚的连衣裙，适合各种场合。',
    price: 499,
    picture: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.uz_AnnENlaeF20tqy2PjYAAAAA?rs=1&pid=ImgDetMain'
  },
  {
    id: 2,
    name: '修身牛仔裤',
    desc: '经典的修身牛仔裤，百搭又舒适。',
    price: 399,
    picture: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.uz_AnnENlaeF20tqy2PjYAAAAA?rs=1&pid=ImgDetMain'
  },
  {
    id: 3,
    name: '商务衬衫',
    desc: '高品质的商务衬衫，尽显专业气质。',
    price: 299,
    picture: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.uz_AnnENlaeF20tqy2PjYAAAAA?rs=1&pid=ImgDetMain'
  },
  {
    id: 4,
    name: '休闲外套',
    desc: '时尚休闲的外套，保暖又时尚。',
    price: 599,
    picture: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.uz_AnnENlaeF20tqy2PjYAAAAA?rs=1&pid=ImgDetMain'
  },
  {
    id: 5,
    name: '运动套装',
    desc: '舒适的运动套装，适合运动和休闲。',
    price: 499,
    picture: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.uz_AnnENlaeF20tqy2PjYAAAAA?rs=1&pid=ImgDetMain'
  },
    {
    id: 6,
    name: '运动套装',
    desc: '舒适的运动套装，适合运动和休闲。',
    price: 499,
    picture: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.uz_AnnENlaeF20tqy2PjYAAAAA?rs=1&pid=ImgDetMain'
  }
]);

const category = ref([])
function categoryListByShop() {
  getCategoryByShop().then(
    res => {
      console.log(res.data);
      category.value = res.data;
    }
  )
}
categoryListByShop();

function goodListByShop() {
  getGoodsByShop().then(
    res => {
      console.log(res.data);
      goodlist.value = res.data;
    }
  )
}
goodListByShop();

function goodListByCategory(categoryNmae) {
  getGoodsByCategory(categoryNmae).then(
    res => {
      console.log(res.data);
      goodlist.value = res.data;
    }
  )
}
goodListByCategory('衬衫');

function searchGoods(search) {
  searchShopGoods(search).then(
    res => {
      console.log(res.data);
      goodlist.value = res.data;
    }
  )
}

const tabPosition = ref('left');
const tabs = ref([
  { name: '衬衫', id: 1 },
  { name: '卫衣', id: 2 },
  { name: '上装', id: 3 },
  { name: '下装', id: 4 }
]);
</script>

<template>
    <LayoutNav></LayoutNav>
    <header class='app-header'>
    <div class="container">
      <div class="logo">
        <RouterLink to="/">桃禧</RouterLink>
      </div>
      <div class="app-header-nav">
        <el-input v-model="search" placeholder="输入您想要的商品" size="big" clearable style="padding: 15px 30px ;"></el-input>
      </div>
      <ul class="search">
        <el-button type="button" size="big" style="background-color: #e58686;color: #000;margin-top: -24px;"
            @click="searchGoods">
            搜索
            <i class="iconfont icon-search"></i>
        </el-button>
      </ul>
    </div>
  </header>
  <hr>

  <div class="container">
      <div class="shop-header" :model="shop">
        <div class="box-left">
            <div class="left-img">
              <img
                class="shop-img"
                :src="shop.logo" />
            </div>
        </div>
        <div class="box1">
          <div class="shop-container">
            <ul>
            <h2 class="name">{{ shop.name }}</h2>
            <li class="desc">{{ shop.desc }}</li>
            <li class="">综合服务
              <el-rate
                v-model="shop.rate"
                disabled
                show-score
                text-color="#ff9900"
              />
            </li>
            <li>店铺热线<span style="margin-left: 10px;">{{ shop.phone }}</span></li>
            <li class="location">{{ shop.location }}</li>    
            </ul>
          </div>
        </div>
      </div>
      <div class="box2">
        <div class="side">
          <h2>全部宝贝</h2>
          <!-- <div  v-for="item in category" :key="item" @click="goodListByCategory(item.categoryNmae)">
            <span >{{ item.categoryNmae }}</span>
          </div> -->
          <el-tabs :tab-position="tabPosition" class="category-tabs">
            <el-tab-pane v-for="tab in tabs" :key="tab.id" :label="tab.name"></el-tab-pane>
          </el-tabs>
        </div>

        <div class="home-product">
          <div class="goodList-box">
            <ul class="goods-list">
              <li v-for="good in goodlist" :key="good.id">
                <RouterLink :to="{name: 'gooddetail', params: {goodid: good.id}}" class="goods-item">
                <img :src="good.picture" alt="" />
                  <p class="name ellipsis">{{ good.name }}</p>
                  <p class="desc ellipsis">{{ good.desc }}</p>
                  <p class="price">&yen;{{ good.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </div>
        </div>

      </div>
    </div>

    <LayoutFooter></LayoutFooter>
</template>

<style scoped lang='scss'>
  .shop-container{
    ul{
      h2{
        margin-bottom: 10px;
      }
    }
    li{
      margin-bottom: 10px;
    }
    .location{
      color:#999
    }
    .desc{
      margin-bottom: 0;
    }
  }


    .home-product {
      background: #fff;
      margin: 3px 10px 18px 10px;
      display: flex;

      .cover {
        width: 220px;
        height: 610px;
        margin-right: 10px;
        position: relative;

        img {
          width: 100%;
          height: 100%;
        }

        .label {
          width: 188px;
          height: 66px;
          display: flex;
          font-size: 18px;
          color: #fff;
          line-height: 66px;
          font-weight: normal;
          position: absolute;
          left: 0;
          top: 50%;
          transform: translate3d(0, -50%, 0);

          span {
            text-align: center;

            &:first-child {
              width: 76px;
              background: rgba(0, 0, 0, 0.9);
            }

            &:last-child {
              flex: 1;
              background: rgba(0, 0, 0, 0.7);
            }
          }
        }
      }


      .goods-list {
        width: 1000px;
        display: flex;
        flex-wrap: wrap;

        li {
          width: 240px;
          height: 300px;
          margin-right: 10px;
          margin-bottom: 10px;

          &:nth-last-child(-n + 4) {
            margin-bottom: 0;
          }

          &:nth-child(4n) {
            margin-right: 0;
          }
        }
      }

      .goods-item {
        display: block;
        width: 240px;
        padding: 20px 30px;
        text-align: center;
        transition: all .5s;
        background: #fff;
        box-shadow: 0 4px 8px 0 rgba(0, 0, 0, .08);


        &:hover {
          transform: translate3d(0, -3px, 0);
          box-shadow: 2px 3px 8px rgb(0 0 0 / 20%);
        }

        img {
          width: 160px;
          height: 160px;
        }

        p {
          padding-top: 10px;
        }

        .name {
          font-size: 16px;
        }

        .desc {
          color: #999;
          height: 29px;
        }

        .price {
          color: $priceColor;
          font-size: 20px;
        }
      }
    }


.app-header {
  background: #ffffff;

  .container {
    display: flex;
    padding-left: 15%;
    // align-items: center;
  }

  .logo {
    width: 60px;
    margin-top: -15px;

    a {
      display: block;
      height: 80px;
      width: 100%;
      text-indent: -9999px;
      background: url('@/assets/images/logo.png') no-repeat center 18px / contain;
    }
  }

  .app-header-nav {
    width: 600px;
    // display: flex;
    padding-left: 50px;
    // position: relative;
    // z-index: 998;
  
  }

  .search {
    width: 300px;
    height: 32px;
    padding-left: 5px;
    line-height: 80px;

    .icon-search {
      font-size: 18px;
    }

    input {
        color: #000;
    }
  }

}

  ::v-deep .el-tabs__nav{
    width: 150px;
  }
    /* 内容文字 */
  ::v-deep .el-tabs__item {
    padding: 20px !important; //内容与padding框的距离
    margin-right: 20px;
    height: 50px;
    font-size: 20px !important; //更改选项卡标签的字体大小
  }

// 商品栏
// #goods-shelf{
//   margin: 5px 30px;
//   height: 775px;
//   width: 100%;
//   display: grid;
//   grid-template-columns: repeat(auto-fill, 220px);
//   overflow: hidden;
//   background-color: #ffffff;
//   border-radius: 5px;
//   .good-box{
//     margin: 35px 50px;
//     width: 200px;
//     height: 280px;
//     box-shadow: 3px 3px 3px 3px #ff89aa;
//     background-color: #d3dce6;
//   }
//   .good-img{
//     width: 100%;
//     height: 80%;
//   }
//   .good-name{
//     // margin-left: 20%;
//     text-align: center;
//     border: none;
//     background-color: #d3dce6;
//   }
//   p{
//     margin: 5px;
//   }

// }


      .shop-header {
        width: 1137px;
        height: 171px;
        margin-left: calc(50% - 572px);
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        z-index: 1;
        margin-top: 10px;
        overflow: hidden;
        background-color: #ffffff;
        border-radius: 15px;
      }

      .box-left {
        position: relative;
        width: 131px;
        height: auto;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        margin-left: 59px;
        margin-top: 20px;
        margin-bottom: 20px;
        align-self: stretch;
      }

      .left-img {
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0%;
        left: 0%;
        overflow: hidden;
        border-radius: 32px;
        border-width: 1px 1px 1px 1px;
        border-style: solid;
        border-color: var(--, #ffffff);
        right: 0%;
        bottom: 0%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
      }

      .shop-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      .box1 {
        position: relative;
        width: 800px;
        height: 170px;
        margin-left: 60px;
      }

      .box2 {
        display: flex;
        height: 800px;
        margin-top: 15px;
        justify-content: center;
      }

      .side {
        width: 150px;
        height: 780px;
        background-color: #ffffff;
        border-radius: 5px;
        h2{
          margin-left: 20px;
        }
      }


</style>